package com.itheima01.day08;

import java.util.Scanner;

/**
 * @author 刘全
 * @date 2021/7/9
 */
/*
需求：已知用户名和密码，请用程序实现模拟用户登录。总共给三次机会，登录之后，给出相应的提示
 */
public class User {
    private String userName;
    private String passWord;

    public User() {
    }

    public User(String userName, String passWord) {
        this.userName = userName;
        this.passWord = passWord;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }

    public void onLine() {
        Scanner sc = new Scanner(System.in);
        int i = 3;
        String s1 = "lq";
        String s2 = "990922";
        System.out.println("您有" + i + "次登录机会,次数用完将无法登录,请小心输入");
        for (; i > 0; i--) {
            System.out.println("请输入用户名");
            userName = sc.next();
            System.out.println("请输入密码");
            passWord = sc.next();
            if (s1.equals(userName) && s2.equals(passWord)) {
                System.out.println("用户名密码正确,欢迎使用!");
                break;
            } else {
                if (i != 1) {
                    System.out.println("您的用户名或密码错误,请重新输入!您还有" + (i - 1) + "次机会");
                } else {
                    System.out.println("您的次数已用完,请明天再来!");
                }
            }
        }
    }
}
